﻿namespace TomatoBreak.UnitSpecs.DomainObjects
{
    using System;

    using Machine.Specifications;

    using Infrastructure;
    using TomatoBreak.DomainObjects;

    public abstract class TaskSpec
    {
        protected const string Name = "Dummy";
        protected static readonly User User = ObjectMother.CreateUser();
    }

    [Subject(typeof(Task))]
    public class when_creating_task_with_null_user : TaskSpec
    {
        static Exception exception;

        Because of = () => exception = Catch.Exception(() => new Task(null, Name, Clock.UtcNow()));

        It should_throw_exception = () => exception.ShouldBeOfType<ArgumentNullException>();
    }

    [Subject(typeof(Task))]
    public class when_creating_task_with_null_or_blank_name : TaskSpec
    {
        static Exception exception;

        Because of = () => exception = Catch.Exception(() => new Task(User, string.Empty, Clock.UtcNow()));

        It should_throw_exception = () => exception.ShouldBeOfType<ArgumentNullException>();
    }

    public abstract class CreatedTaskSpec : TaskSpec
    {
        protected static Task task;

        Establish context = () => task = new Task(User, Name, Clock.UtcNow());
    }

    [Subject(typeof(Task))]
    public class when_task_is_created : CreatedTaskSpec
    {
        It should_have_same_name_which_is_passed_in_constructor = () => task.Name.ShouldEqual(Name);

        It should_have_same_user_which_is_passed_in_constructor = () => task.User.ShouldBeTheSameAs(User);

        It should_be_planned = () => task.Planned.ShouldBeTrue();
    }
}